package com.atos.howl.chaos.web.controller.file;

import com.atos.howl.chaos.enums.ChaosSysCodeEnum;
import com.atos.howl.chaos.pdm.dto.upload.UploadImgDTO;
import com.atos.howl.chaos.pdm.service.UploadService;
import com.atos.howl.chaos.utils.ChaosUtils;
import com.atos.howl.chaos.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping("/api/fileController")
public class FileController {
//
////    @Resource
////    //private UserMapper userMapper;
//    @Autowired
//    private LoginService loginService;
    @Autowired
    private UploadService uploadService;
//
    @PostMapping("/uploadHeadImg")
    @ResponseBody
    public ChaosSysCodeEnum uploadHeadImgFile(@RequestBody UploadImgDTO uploadImgDTO){

       String loginUserUUID =  ChaosUtils.getLoginUserUUID();

        String headImgBase64 = uploadImgDTO.getImgBase64();
        uploadService.uploadHeadImg(headImgBase64,loginUserUUID);
        return ChaosSysCodeEnum.UPLOAD_SUCCESS;
    }
//    public LoginResultDTO login(@RequestBody @Valid User user){
//        boolean isAccountExist = loginService.isAccountExist(user);
//        LoginResultDTO result = new LoginResultDTO();
//
//        if(isAccountExist)
//        {
//            //登陆成功,添加状态码
//            result.setChaosCode(ChaosSysCodeEnum.SUCCESS.getChaosCode());
//            result.setChaosCodeDesc(ChaosSysCodeEnum.SUCCESS.getChaosCodeDesc());
//            //使用账号和密码以及token生成器生成一个token
//            String chaosToken = TokenUtils.sign(user.getAccount(),user.getPassword());
//            result.setChaosToken(chaosToken);
//        }
//
//        if(!isAccountExist)
//        {
//            //登陆失败，也添加状态码
//            result.setChaosCode(ChaosSysCodeEnum.ERROR01.getChaosCode());
//            result.setChaosCodeDesc(ChaosSysCodeEnum.ERROR01.getChaosCodeDesc());
//        }
//
//
//
//        //result.setLoginSuccess(isAccountExist);
//        return result;
//    }
}
